package com.pzhu.controller.wx;

import com.pzhu.model.dto.OrderDto;
import com.pzhu.model.dto.OrderParamDto;
import com.pzhu.model.entity.Order;
import com.pzhu.model.help.ResponseResult;
import com.pzhu.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author : zqh
 * @Date : 2023/12/21 0021 下午 8:28
 * @Version: 1.0
 */
@Api(tags = "订单接口")
@RestController
@RequestMapping("/wx/order")
public class WxOrderController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("添加订单信息")
    @PostMapping("/pay")
    public ResponseResult saveAddress(@RequestBody @Valid OrderDto orderDto){
        return orderService.pay(orderDto);
    }

    @ApiOperation("查询所有订单")
    @GetMapping("/getOrder")
    public ResponseResult getOrderByStatus(Integer status){
        return orderService.getOrder(status);
    }


    @ApiOperation("查询所有没有派送成功的订单")
    @GetMapping("/undelivered")
    public ResponseResult undelivered(OrderParamDto orderParamDto){
        return orderService.undelivered(orderParamDto);
    }


    @ApiOperation("根据ID查询详情")
    @GetMapping("/getById/{id}")
    @ApiImplicitParam(name = "id",value = "订单ID",required = true)
    public ResponseResult getById(@PathVariable(value = "id") Long id){
        Order order = orderService.getById(id);

        Map<String,Object> map = new HashMap<>();
        map.put("order",order);
        return ResponseResult.ok(map);
    }
}
